package com.itheima.controller;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.entity.Result;
import com.itheima.service.ReportService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

@RestController
@RequestMapping("/report")
public class ReportController {
    @Reference
    ReportService reportService;

    @RequestMapping("/getMemberReport")
    public Result getMemberReport() {
        DateTime dateTime = DateUtil.offsetMonth(new Date(), -12);
        List<String> months = new ArrayList<>();
        for (int i = 3; i < 6; i++) {
            months.add(DateUtil.offsetMonth(dateTime, i).toString("yyyy-MM"));
        }

        List<Integer> memberCount = reportService.getMemberReport(months);
        Map map = new HashMap<>();
        map.put("months", months);
        map.put("memberCount", memberCount);
        return Result.success("", map);
    }

    @RequestMapping("/getSetmealReport")
    public Result getSetmealReport() {
        List<Map> maps = reportService.getSetmealReport();
        return Result.success("", maps);
    }


    public static void main(String[] args) {
        DateTime dateTime = DateUtil.offsetMonth(new Date(), -12);
//        System.out.println(dateTime.toString("yyyy-MM"));
        List<String> months = new ArrayList<>();
        for (int i = 0; i < 12; i++) {
            months.add(DateUtil.offsetMonth(dateTime, i).toString("yyyy-MM"));
        }
        System.out.println(months);
    }
}
